package cn.juforg.gobang.interfaces;

import java.util.List;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.FloatMath;
import android.util.Log;
import android.view.MotionEvent;
import cn.juforg.gobang.Chess;
import cn.juforg.gobang.ChessBoard;
import cn.juforg.gobang.Line;
import cn.juforg.gobang.ZoomPoint;
import cn.juforg.gobang.player.BasePlayer;

public class ChessBoardImpl implements ChessBoardDao {

	@Override
	public boolean isMyTurn(BasePlayer player, boolean currentPlayer) {
		return false;
	}

	@Override
	public void drawChssboardLines(List<Line> lines, Canvas canvas, Paint paint) {
	}

	@Override
	public void drawChess(Canvas canvas, int[][] chessArray,
			Bitmap[] chessColorArray, Paint paint) {
	}

	@Override
	public void restart() {
	}

	@Override
	public boolean isRunning(int currentStatus) {
		return false;
	}

	@Override
	public void playerRun(BasePlayer player, MotionEvent event) {
	}

	@Override
	public void playerRun(BasePlayer player, Chess chess) {
	}

	@Override
	public Chess generateChess(Float x, Float y) {
		return null;
	}

	@Override
	public void setPlayerRun(BasePlayer player) {
		
	}

	@Override
	public void setPlayerRun(boolean playerFlag) {
	}

	@Override
	public void refressCanvas() {
	}

	@Override
	public void fillChessArrays(Bitmap[] chessColorArray, int color,
			Drawable drawable, int chessSize) {
		
	}
	public void refreshChessArrays(Bitmap[] chessColorArray,int chessSize) {
		for (Bitmap bitmap : chessColorArray) {
			bitmap = Bitmap.createScaledBitmap(bitmap, chessSize, chessSize, true);
		}

	}

	@Override
	public void setStatus(int newStatus) {
	}

	@Override
	public boolean setChess(Chess chess, BasePlayer player) {
		return false;
	}
	
	@Override
	public void zoomChessBoard(float zoomRatio) {
		
	}

	public static void zoomNet(ChessBoard chessBoard){
		/*List<Line> lines = new ArrayList<Line>();
    	for (int i = 0; i <= maxX; i++) {//竖线
    		lines.add(new Line(xOffset+i*chessSize-chessSize/2, yOffset, xOffset+i*chessSize-chessSize/2, yOffset+maxY*chessSize));
		}
    	for (int i = 0; i <= maxY; i++) {//横线
    		lines.add(new Line(xOffset, yOffset+i*chessSize-chessSize/2, xOffset+maxX*chessSize, yOffset+i*chessSize-chessSize/2));
		}*/
	}
	
	public static Chess generateChess(float x, float y){
		Chess  chess = new Chess(0,0);
		chess.setX(Math.round(x * ChessBoard.maxX / ChessBoard.screen_width)+ ChessBoard.zoomXOffset);
		chess.setY(Math.round(y * ChessBoard.maxY / ChessBoard.screen_height)+ ChessBoard.zoomXOffset);
		return chess;
	}
	
	public static float getTwoPointDistance(MotionEvent event) {
	    float x = event.getX(0) - event.getX(1);
	    float y = event.getY(0) - event.getY(1);
	    return FloatMath.sqrt(x * x + y * y);
	} 
	
	//计算中点位置 
    public static void generateMidPoint(MotionEvent event) {
    	float x = event.getX(0) + event.getX(1); 
    	float y = event.getY(0) + event.getY(1); 
    	ZoomPoint.getInstance().set(x / 2, y / 2); 
    	ChessBoard.zoomChess = ChessBoardImpl.generateChess(x / 2, y / 2);
   }
}
